/**
 *
 */
import Util;
import OpenApi;

import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('location', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model DescribeEndpointRequest {
  id?: string(name='Id'),
  serviceCode?: string(name='ServiceCode'),
  password?: string(name='Password'),
}

model DescribeEndpointResponseBody = {
  type?: string(name='Type'),
  requestId?: string(name='RequestId'),
  endpoint?: string(name='Endpoint'),
  namespace?: string(name='Namespace'),
  serivceCode?: string(name='SerivceCode'),
  id?: string(name='Id'),
  protocols?: {
    protocols?: [ string ](name='Protocols')
  }(name='Protocols'),
}

model DescribeEndpointResponse = {
  headers: map[string]string(name='headers'),
  body: DescribeEndpointResponseBody(name='body'),
}

async function describeEndpointWithOptions(request: DescribeEndpointRequest, runtime: Util.RuntimeOptions): DescribeEndpointResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('DescribeEndpoint', '2015-06-12', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function describeEndpoint(request: DescribeEndpointRequest): DescribeEndpointResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeEndpointWithOptions(request, runtime);
}

model DescribeEndpointsRequest {
  id?: string(name='Id'),
  serviceCode?: string(name='ServiceCode'),
  type?: string(name='Type'),
}

model DescribeEndpointsResponseBody = {
  success?: boolean(name='Success'),
  requestId?: string(name='RequestId'),
  endpoints?: {
    endpoint?: [ 
    {
      type?: string(name='Type'),
      namespace?: string(name='Namespace'),
      serivceCode?: string(name='SerivceCode'),
      id?: string(name='Id'),
      endpoint?: string(name='Endpoint'),
      protocols?: {
        protocols?: [ string ](name='Protocols')
      }(name='Protocols'),
    }
  ](name='Endpoint')
  }(name='Endpoints'),
}

model DescribeEndpointsResponse = {
  headers: map[string]string(name='headers'),
  body: DescribeEndpointsResponseBody(name='body'),
}

async function describeEndpointsWithOptions(request: DescribeEndpointsRequest, runtime: Util.RuntimeOptions): DescribeEndpointsResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('DescribeEndpoints', '2015-06-12', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function describeEndpoints(request: DescribeEndpointsRequest): DescribeEndpointsResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeEndpointsWithOptions(request, runtime);
}

model DescribeRegionsRequest {
  password?: string(name='Password'),
}

model DescribeRegionsResponseBody = {
  totalCount?: int32(name='TotalCount'),
  requestId?: string(name='RequestId'),
  regionIds?: {
    regionIds?: [ string ](name='RegionIds')
  }(name='RegionIds'),
}

model DescribeRegionsResponse = {
  headers: map[string]string(name='headers'),
  body: DescribeRegionsResponseBody(name='body'),
}

async function describeRegionsWithOptions(request: DescribeRegionsRequest, runtime: Util.RuntimeOptions): DescribeRegionsResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('DescribeRegions', '2015-06-12', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function describeRegions(request: DescribeRegionsRequest): DescribeRegionsResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeRegionsWithOptions(request, runtime);
}

model DescribeServicesRequest {
  regionId?: string(name='RegionId'),
  password?: string(name='Password'),
}

model DescribeServicesResponseBody = {
  totalCount?: int32(name='TotalCount'),
  requestId?: string(name='RequestId'),
  services?: {
    services?: [ string ](name='Services')
  }(name='Services'),
}

model DescribeServicesResponse = {
  headers: map[string]string(name='headers'),
  body: DescribeServicesResponseBody(name='body'),
}

async function describeServicesWithOptions(request: DescribeServicesRequest, runtime: Util.RuntimeOptions): DescribeServicesResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('DescribeServices', '2015-06-12', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function describeServices(request: DescribeServicesRequest): DescribeServicesResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeServicesWithOptions(request, runtime);
}

model ListEndpointsRequest {
  namespace?: string(name='Namespace'),
  id?: string(name='Id'),
  serivceCode?: string(name='SerivceCode'),
}

model ListEndpointsResponseBody = {
  success?: boolean(name='Success'),
  requestId?: string(name='RequestId'),
  endpointList?: {
    itemEndpoint?: [ 
    {
      type?: string(name='Type'),
      namespace?: string(name='Namespace'),
      product?: string(name='Product'),
      id?: string(name='Id'),
      endpoint?: string(name='Endpoint'),
      protocols?: {
        protocols?: [ string ](name='Protocols')
      }(name='Protocols'),
    }
  ](name='ItemEndpoint')
  }(name='EndpointList'),
}

model ListEndpointsResponse = {
  headers: map[string]string(name='headers'),
  body: ListEndpointsResponseBody(name='body'),
}

async function listEndpointsWithOptions(request: ListEndpointsRequest, runtime: Util.RuntimeOptions): ListEndpointsResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('ListEndpoints', '2015-06-12', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function listEndpoints(request: ListEndpointsRequest): ListEndpointsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listEndpointsWithOptions(request, runtime);
}

model ListEndpointsByIpRequest {
  ip?: string(name='Ip'),
}

model ListEndpointsByIpResponseBody = {
  success?: boolean(name='Success'),
  requestId?: string(name='RequestId'),
  endpointList?: {
    itemEndpoint?: [ 
    {
      type?: string(name='Type'),
      namespace?: string(name='Namespace'),
      product?: string(name='Product'),
      id?: string(name='Id'),
      endpoint?: string(name='Endpoint'),
      protocols?: {
        protocols?: [ string ](name='Protocols')
      }(name='Protocols'),
    }
  ](name='ItemEndpoint')
  }(name='EndpointList'),
}

model ListEndpointsByIpResponse = {
  headers: map[string]string(name='headers'),
  body: ListEndpointsByIpResponseBody(name='body'),
}

async function listEndpointsByIpWithOptions(request: ListEndpointsByIpRequest, runtime: Util.RuntimeOptions): ListEndpointsByIpResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('ListEndpointsByIp', '2015-06-12', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function listEndpointsByIp(request: ListEndpointsByIpRequest): ListEndpointsByIpResponse {
  var runtime = new Util.RuntimeOptions{};
  return listEndpointsByIpWithOptions(request, runtime);
}

